package com.shushan.mixedexam.adapter;

import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.shushan.pages.newtype.bean.ExampleSentenceBean;
import com.shushan.shushanbao.R;
import com.shushan.util.StringTools;

import java.util.List;

/**
 * @ClassName: EnglishWordsStudyRecyclerAdapter
 * @Desciption: //英语单词学习fragment recyclerView的适配器
 * @author: zhangshihao
 * @date: 2018-06-28
 */
public class EnglishWordsStudyRecyclerAdapter extends RecyclerView.Adapter<EnglishWordsStudyRecyclerAdapter.ViewHolder>{

    private String newWord;
    private List<ExampleSentenceBean> exampleSentenceBeans;

    public EnglishWordsStudyRecyclerAdapter(String new_word,List<ExampleSentenceBean> exampleSentenceBeans){
        this.newWord = new_word;
        this.exampleSentenceBeans = exampleSentenceBeans;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_english_word_study_recycler,null,false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        ExampleSentenceBean sentenceBean = exampleSentenceBeans.get(position);
        holder.tvIndex.setText((position+1)+".");


        StringTools.setSpan(newWord,sentenceBean.english_name,Color.parseColor("#FF502E"),holder.tvEnglishSentence);
//        holder.tvEnglishSentence.setText(sentenceBean.english_name);
        holder.tvChineseSentence.setText(sentenceBean.chinese_name);
    }

    @Override
    public int getItemCount() {
        return exampleSentenceBeans.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        private TextView tvIndex;
        private TextView tvEnglishSentence;
        private TextView tvChineseSentence;
        public ViewHolder(View itemView) {
            super(itemView);
            tvIndex = itemView.findViewById(R.id.tv_item_index);
            tvEnglishSentence = itemView.findViewById(R.id.tv_english_sentence);
            tvChineseSentence = itemView.findViewById(R.id.tv_chinese_sentence);
        }
    }
}